package com.s10.tree;

import com.s10.tree.BinarySearchTree.TreeNode;

public class BinarySearchTreeTest {

	public static void main(String[] args) {
		BinarySearchTree tree = new BinarySearchTree();
		// - - - 5
		// - - -3 9
		// - - 2 4
		// - -1
		tree.insert(5);
		tree.insert(3);
		tree.insert(9);
		tree.insert(2);
		tree.insert(4);
		tree.insert(1);
		tree.foreach();

		System.out.println("find(0) = " + tree.find(0));
		System.out.println("find(1) = " + tree.find(1));
		System.out.println("find(2) = " + tree.find(2));

		System.out.println("min = " + tree.findMin());
		System.out.println("max = " + tree.findMax());

		System.out.println("-----------");
		System.out.println(tree.delete(5));
		tree.foreach();
		System.out.println("-----------");
		System.out.println(tree.delete(9));
		tree.foreach();
		System.out.println("-----------");
		System.out.println(tree.delete(2));
		tree.foreach();
		System.out.println("-----------");
		System.out.println(tree.delete(4));
		tree.foreach();
		System.out.println("-----------");
		System.out.println(tree.delete(1));
		tree.foreach();
		System.out.println("-----------");
		System.out.println(tree.delete(3));
		tree.foreach();
		System.out.println("-----------");

		TreeNode rootNode = new TreeNode(1);
		TreeNode node2 = new TreeNode(2);
		TreeNode node3 = new TreeNode(3);
		TreeNode node4 = new TreeNode(4);
		TreeNode node5 = new TreeNode(5);
		TreeNode node6 = new TreeNode(6);
		TreeNode node7 = new TreeNode(7);

		rootNode.left = node2;
		rootNode.right = node3;

		node2.left = node4;
		node2.right = node5;

		node3.left = node6;
		node3.right = node7;

		BinarySearchTree.qian(rootNode);
		System.out.println("");
		System.out.println("-----------");

		BinarySearchTree.zhong(rootNode);
		System.out.println("");
		System.out.println("-----------");

		BinarySearchTree.hou(rootNode);
		System.out.println("");
		System.out.println("-----------");
	}
}
